package _07Stream流常用方法;

import java.util.function.Consumer;
import java.util.stream.Stream;


/**
 * @author Asin
 */
public class DemoStreamMethod {
    public static void main(String[] args) {



        //count方法，统计数据的数量
        Stream<Integer> streamCount = Stream.of(11, 22, 33, 44, 55, 66);
        long count = streamCount.count();
        System.out.println(count);
        System.out.println("=================");

        //forEach方法，遍历取出数据，遍历一次后数据使用完这个流中就不存在数据了
        Stream<Integer> streamForEach = Stream.of(11, 22, 33, 44, 55, 66);
        streamForEach.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println(integer);
            }
        });

        //lambda简化forEach方法
        //stream.forEach( integer -> System.out.println(integer));

        //方法引用继续简化
        //stream.forEach( System.out::println);
        System.out.println("=================");


        //filter过滤方法
        Stream<Integer> streamFilter = Stream.of(11, 22, 33, 44, 55, 66);
        //筛选出偶数并且遍历
        streamFilter.filter(integer -> integer % 2 == 0).forEach(System.out::println);


        //limit，截取前n个方法
        Stream<Integer> streamLimit = Stream.of(11, 22, 33, 44, 55, 66);
        streamLimit.limit(3).forEach(System.out::println);

        System.out.println("=====================");

        //skip方法，跳过前n个数据
        Stream<Integer> streamSkip= Stream.of(11, 22, 33, 44, 55, 66);
        streamSkip.skip(3).forEach(System.out::println);
       
    }
}
